﻿using System;
using System.Windows.Forms;

namespace PSSymbolStore.Manager.Windows
{
    public partial class TransactionPreview : UserControl
    {
        public TransactionPreview()
        {
            InitializeComponent();
        }

        private AddTransaction _transaction;

        public AddTransaction Transaction
        {
            get { return _transaction; }
            set
            {
                _transaction = value;
                UpdateUI();
            }
        }

        private void UpdateUI()
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)UpdateUI);
                return;
            }

            // Update the UI values
            if (_transaction == null)
            {
                idLabel.Text = String.Empty;
                timestampLabel.Text = String.Empty;
                versionLabel.Text = String.Empty;
                productLabel.Text = String.Empty;
                lockImage.Image = null;
            }
            else
            {
                idLabel.Text = _transaction.TransactionId;
                timestampLabel.Text = _transaction.TransactionDateTime.ToString();
                versionLabel.Text = (String.IsNullOrEmpty(_transaction.Version)) ? "[none]" : _transaction.Version;
                productLabel.Text = (String.IsNullOrEmpty(_transaction.Product)) ? "[none]" : _transaction.Product;
                lockImage.Image = (_transaction.Locked) ? Properties.Resources.LockIcon : null;
            }
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            // Show the light gray border
            BorderStyle = BorderStyle.FixedSingle;

            base.OnMouseEnter(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            // Hide any borders
            BorderStyle = BorderStyle.None;

            base.OnMouseLeave(e);
        }
    }
}
